package cn.elwy.rcp.ui.provider;

import java.util.List;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

import cn.elwy.common.util.FormatUtil;
import cn.elwy.common.util.ReflectUtil;
import cn.elwy.rcp.core.model.ui.entity.Header;

/**
 * 数据转换器默认实现类
 * @author huangsq
 * @version 1.0, 2014-06-23
 * @since 1.0, 2014-06-23
 */
public class DataParserImpl implements DataParser {

  private HeaderConfig configure;
  private List<Header> headers;

  public String[] parseTexts(Object element) {
    return null;
  }

  public Image parseImage(Object element, int columnIndex) {
    Image image = null;
    return image;
  }

  @Override
  public Object[] getChildren(Object parentElement) {
    return null;
  }

  public Color getForeground(Object element, int columnIndex) {
    return null;
  }

  public boolean isSetForeground() {
    return true;
  }

  public Color getBackgroundColor(Object element, int columnIndex) {
    return null;
  }

  public boolean isSetBackground() {
    return true;
  }

  public void setConfigure(HeaderConfig configure) {
    this.configure = configure;
    headers = configure.getHeaders();
  }

  public HeaderConfig getConfigure() {
    return this.configure;
  }

  public Object[] getShowItems(int start, int end, List<?> list) {
    return null;
  }

  @Override
  public String parseText(Object element, int columnIndex) {
    Header header = headers.get(columnIndex);
    String method = header.getMethod();
    if (method == null) {
      method = header.getMethod(element.getClass().getSimpleName());
    }
    Object result = null;
    if (method != null) {
      result = ReflectUtil.getTableColumnValue(element, method, true);
      if (header.getFormatPattern() != null) {
        result = FormatUtil.format(header.getFormatClass(), header.getFormatPattern(), result, "");
      }
    }
    return result == null ? "" : result.toString();
  }

  @Override
  public boolean isChecked(Object element) {
    Object result = null;
    System.out.println(element);
    return result == null;
  }

  @Override
  public boolean isGrayed(Object element) {
    Object result = null;
    System.out.println(element);
    return result == null;
  }

}
